<!--
 * @Author: Allen
 * @Date: 2021-03-04 15:26:38
 * @Description: 抱怨身处黑暗，不如提灯前行。愿你在自己存在的地方，成为一束光，照亮世界的一角
 * @LastEditTime: 2021-03-18 11:36:01
 * @LastEditors: Allen
 * @FilePath: \dmocdms_webend\src\views\se\basicData\warrantyPeriodSetting\edit2.vue
 * @Additional: 附加类容
-->
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="40%"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :span="comp.span || 24"
            :is-mul="comp.isMul"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :date-options-type="comp.dateOptionsType"
            :is-call-back="comp.isCallBack"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/wms/mixins/formMixins'
import { seApi } from '@/api/seApi/baseData'
import storage from '@/utils/storage'
export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader') // 弹窗标题
  },
  // 组件混入对象
  mixins: [formMixins],
  props: {
    propData: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: seApi.addGuaranteeTime,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.save(),
          text: '保存' // "保存"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: 'edit_compKey1',
          labelName: '保修分类：', // 仓库名称
          codeField: 'parTimeClass',
          component: () => import('@/components/wms/dropdownList/dropdownList'),
          type: 'dropdownList',
          isMust: true,
          isMul: false,
          options: this.propData.partimeClassData,
          isRequire: true
        },
        {
          compKey: 'edit_compKey2',
          labelName: '备件分类：', // "通道编号"
          codeField: 'partClass',
          component: () => import('@/components/wms/dropdownList/dropdownList'),
          type: 'dropdownList',
          isMust: true,
          isRequire: true,
          options: this.propData.partClassData
        },
        {
          compKey: 'edit_compKey3',
          labelName: '保修期里程（KM）：', // "通道编号"
          codeField: 'partMile',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          isRequire: true
        },
        {
          compKey: 'edit_compKey4',
          labelName: '保修期时间（月）：', // "通道编号"
          codeField: 'partTimeLimit',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          isRequire: true
        }
      ],
      // 标题
      textMap: {
        edit: '编辑包装样式管理',
        add: '新增包装样式管理'
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        parTimeClass: '',
        partClass: '',
        partMile: '',
        partTimeLimit: ''
      }
    }
  },
  created() {
    console.log(this.propData)
  },
  methods: {
    // 保存
    save() {
      this.$utils.validataMoth(this, 'validpopup')
      if (this.valid) {
        var saveObj = JSON.parse(JSON.stringify(this.formField))
        console.log(saveObj)
        // 保存表单
        this.saveForm(saveObj, () => {
          this.curPopupsVisible = false
          this.propData.table.queryTable()
        })
        storage.remove(this.$route.query.pageCode)
      }
    }
  }
}
</script>
<style type="text/css" scoped>
.filter-params .el-col label .curName {
  width: 150px;
}
</style>
